package com.api.oa.controller;


import com.api.oa.model.entity.YQFeedBack;
import com.api.oa.services.YQFeedBackService;
import com.api.shopapi.controller.BaseController;
import com.api.shopapi.entity.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/yq/yQFeedBack")
public class YQFeedBackController extends BaseController {

        @Autowired
        private YQFeedBackService iYQFeedBackService;

        @RequestMapping(value = "/add", method = RequestMethod.POST)
        public MyResult Add(@RequestBody YQFeedBack entity) {
            try {
                 return iYQFeedBackService.add(entity) == 1 ? success("提交成功") : failed("操作失败");
            } catch (Exception e) {
                 return anomalous(getExceptionMsg(e));
            }

        }


        @RequestMapping(value = "/remove/{id}", method = RequestMethod.POST)
        public MyResult remove(@PathVariable Long id) {
            try {
                iYQFeedBackService.remove(id);
                return success("删除成功!");
            } catch (Exception e) {
                return anomalous(getExceptionMsg(e));
            }

        }


        @RequestMapping(value = "/update", method = RequestMethod.POST)
        public MyResult update(@RequestBody YQFeedBack entity) {
            try {
                return iYQFeedBackService.update(entity) == 1 ?  success("操作成功") : failed("操作失败");
            } catch (Exception e) {
                return anomalous(getExceptionMsg(e));
            }

        }


        @RequestMapping(value = "/list", method = RequestMethod.GET)
        public MyResult list(@RequestParam(defaultValue = "1") Integer pageIndex,@RequestParam(defaultValue = "20") Integer pageSize,@RequestParam(required = false) String keyWord) {
            try {
                return success(iYQFeedBackService.list(keyWord,pageIndex,pageSize));
            } catch (Exception e) {
                return anomalous(getExceptionMsg(e));
            }
        }


        @RequestMapping(value = "/one/{id}", method = RequestMethod.GET)
        public MyResult one(@PathVariable Long id) {
            try {
                return success(id == null ? null :iYQFeedBackService.one(id));
            } catch (Exception e) {
                return anomalous(getExceptionMsg(e));
            }
        }


}
